package com.naiterui.ehp.bs.b2c.product.controller.inner;

import java.util.Map;
import java.util.Set;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.ehp.bp.bo.medication.MedicationDefaultUsageBO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.b2c.product.exception.ProductExceptionCodes;
import com.naiterui.ehp.bs.b2c.product.service.IMedicineDefaultUsageService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * <pre>
 *      默认用法用量
 * </pre>
 *
 * @author 王泽浩
 * @date 2019-06-21 11:43
 * @since 1.0.0
 */
@Api(tags = {SwaggerTag.DOCTOR + SwaggerTag.MEDICINE_DRUG, SwaggerTag.CMS + SwaggerTag.MEDICINE_DRUG})
@Validated
@RestController
@RequestMapping("b2c/inner/medicine/usage")
public class InnerMedicineDefaultUsageController {
    @Autowired
    private IMedicineDefaultUsageService medicineDefaultUsageService;

    @ApiOperation(value = "根据商品ID集合获取默认用法用量和安全用量")
    @ApiImplicitParam(name = "skuId", value = "药品ID集合", paramType = "body", dataType = "array", required = true)
    @PostMapping("find")
    public ResponseVO<Map<Long, MedicationDefaultUsageBO>> findBySkuId(@NotNull @RequestBody Set<Long> skuId) {
        Map<Long, MedicationDefaultUsageBO> defaultUsageMap = this.medicineDefaultUsageService.findBySkuId(skuId);
        return PublicService.returnResponseVO(defaultUsageMap);
    }

    @ApiOperation(value = "根据商品ID获取默认用法用量和安全用量")
    @ApiImplicitParam(name = "skuId", value = "药品ID集合", paramType = "path", dataType = "long", required = true)
    @GetMapping("get/{skuId}")
    public ResponseVO<MedicationDefaultUsageBO> getBySkuId(@PathVariable("skuId") Long skuId) {
        MedicationDefaultUsageBO defaultUsage = this.medicineDefaultUsageService.getBySkuId(skuId);
        return PublicService.returnResponseVO(defaultUsage);
    }

    /**
     * 新增或修改用法用量
     * @param medicationDefaultUsageBO
     * @return
     */
    @ApiOperation(value = "新增或修改用法用量")
    @PostMapping
    public ResponseVO<Void> insertOrUpdate(@NotNull @RequestBody MedicationDefaultUsageBO medicationDefaultUsageBO) {
        this.medicineDefaultUsageService.insertOrUpdate(medicationDefaultUsageBO);
        return PublicService.returnResponseVO(ProductExceptionCodes.SUCCESS);
    }
}
